<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<div class="bt">设置</div>
		<template>
			<el-tabs v-model="activeName" >
				<el-tab-pane label="首页设置" name="first">
					<tr width="120px" style="font-weight: bold;font-size:16px ;color: black;">模式设置</tr>
					<div class="but">
						<el-button type="primary" class="submit" @click="submit(false)">平板模式</el-button>
						<el-button type="primary" class="submit" @click="submit(true)">pc模式</el-button>
					</div>
					<div class="sz">
						<table style="width: 100%;">
							<tr width="80px" style="font-weight: bold;font-size:16px ;color: black;">首页模块设置</tr>
							<tr>
								<td width="30%">
									<el-checkbox label="syysbj" v-model="qxbtn.syysbj" class="check2">预设班级模块</el-checkbox>
								</td>
								<td width="30%">
									<el-checkbox label="syzsbj" v-model="qxbtn.syzsbj" class="check2">正式班级模块</el-checkbox>
								</td>
								<td width="30%">
									<el-checkbox label="syjscj" v-model="qxbtn.syjscj" class="check2">待办事项</el-checkbox><!--、催缴纪录模块-->
								</td>
							</tr>
						</table>
					</div>
					<div class="qd" style="width: 100%;margin: 0 auto;text-align: center;margin-top: 20px;">
						<el-button type="primary" class='submit' @click="getCheckedKeys" >确 定</el-button>
						<el-button type="danger"  class='submit' @click="cancel">退出</el-button>
					</div>
				</el-tab-pane>
				<el-tab-pane label="个性化菜单" name="second">
					<div class="left" style="float: left;width: 50%;">
					置顶菜单1
					<el-select v-model="c1" clearable  placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label" >
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					<br />
					
					置顶菜单2
					<el-select v-model="c2" clearable placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label">
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					<br />
					
					置顶菜单3
					<el-select v-model="c3" clearable placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label">
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					<br />
					</div>
					
					<div class="right" style="float: right;width: 50%;">
					置顶菜单4
					<el-select v-model="c4" clearable placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label">
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					<br/>
					
					置顶菜单5
					<el-select v-model="c5" clearable placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label">
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					<br />
					
					置顶菜单6
					<el-select v-model="c6" clearable placeholder="请选择">
						<el-option-group v-for="group in lsgnmklist" :key="group.label" :label="group.label">
							<el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-option-group>
					</el-select> 
					</div>
					<div class="qd" style="width: 100%;margin: 0 auto;text-align: center;margin-top: 20px;">
						<el-button type="primary" class='submit' @click="getzdycdlist" >确 定</el-button>
						<el-button type="danger"  class='submit' @click="cancel">退出</el-button>
					</div>
				</el-tab-pane>
				<el-tab-pane label="消息订阅" name="third"  >
					<div class="sz">
						<table style="width: 100%;">
							<tr width="120px" style="font-weight: bold;font-size:16px ;color: black;">消息订阅设置</tr>
							<tr v-for = 'i in xxdylist'>
								<td >
									 <el-checkbox-group v-model="checkList">
									 <el-checkbox :label="i.cd"  class="check2">{{i.mc}}</el-checkbox>
									 </el-checkbox-group>
								</td>
							</tr>
							</tr>
						</table>
					</div>
					<div class="qd" style="width: 100%;margin: 0 auto;text-align: center;margin-top: 20px;">
						<el-button type="primary" class='submit' @click="xxdy" >确 定</el-button>
						<el-button type="danger" class='submit' @click="cancel">退出</el-button>
					</div>
				</el-tab-pane>
			</el-tabs>
		</template>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				ifxs:'',
				checkList:[],
				str:[],
				xxdylist:[],
				c1:'',
				c2:'',
				c3:'',
				c4:'',
				c5:'',
				c6:'',
				activeName:'first',
				qxbtn: {
					//权限
					syysbj: false,
					syzsbj: false,
					syjscj: false,
					sykbqqbk: false,
					sycwtj: false,
					sylscwtfsh: false,
					sykscjtj: false,
				},
				lsgnmklist:[],
				dialogTableVisible: true
			}
		},
		created() {
			var logininfo = JSON.parse(localStorage.logininfo);
			var str = logininfo.mkids;
			this.getxxdy();
			this.getxxdyxq();
			this.getgxhcdinfo();
			this.getlsgnmk();
			//首页模块
			if(str){
				if(str.indexOf("syysbj") != -1) this.qxbtn.syysbj = true;
				if(str.indexOf("syzsbj") != -1) this.qxbtn.syzsbj = true;
				if(str.indexOf("syjscj") != -1) this.qxbtn.syjscj = true;
				if(str.indexOf("sykbqqbk") != -1) this.qxbtn.sykbqqbk = true;
				if(str.indexOf("sycwtj") != -1) this.qxbtn.sycwtj = true;
				if(str.indexOf("sylscwtfsh") != -1) this.qxbtn.sylscwtfsh = true;
				if(str.indexOf("sykscjtj") != -1) this.qxbtn.sykscjtj = true;
			}
		},
		methods: {
		getlsgnmk () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo) ;
            var params3 = qs.stringify({
              yhid:logininfo.id,
              xxid:logininfo.xxid
			});
              this.searchLoading = true;
              this.axios.post(this.$store.state.api + 'ls/getlsgnmk',params3)
              .then( res => {
              	  this.lsgnmklist = res.data.data.list
                  this.searchLoading = false;
              }).catch( res => {
                  this.searchLoading = false;
              })
          },
			getxxdyxq () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo);
            var params3 = qs.stringify({
              yhid:logininfo.id,
              xxid:logininfo.xxid
			});
              this.searchLoading = true;
              this.axios.post(this.$store.state.api + 'ls/xxdyzs',params3)
              .then( res => {
                    	var add = res.data.data.list[0].xxdy
                    	var arr = add.split(',')
                    	this.checkList = arr
                        this.searchLoading = false;
              }).catch( res => {
                  this.searchLoading = false;
              })
          },
          getgxhcdinfo () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo);
            var params3 = qs.stringify({
              yhid:logininfo.id,
              xxid:logininfo.xxid
			});
              this.searchLoading = true;
              this.axios.post(this.$store.state.api + 'ls/getgxhcdinfo',params3)
              .then( res => {
                    	var gxh = res.data.data.list[0].code
                    	var gxharr = gxh.split(',')
                    	for(var i in gxharr){
                    		this.c1 = gxharr[0]
                    		this.c2 = gxharr[1]
                    		this.c3 = gxharr[2]
                    		this.c4 = gxharr[3]
                    		this.c5 = gxharr[4]
                    		this.c6 = gxharr[5]
                    	}
                  this.searchLoading = false;
              }).catch( res => {
                  this.searchLoading = false;
              })
          },
	     	getxxdy () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo) ;
            var params3 = qs.stringify({
              yhid:logininfo.id,
              xxid:logininfo.xxid
			});
              this.searchLoading = true;
              this.axios.post(this.$store.state.api + 'ls/getxxdy',params3)
              .then( res => {
						console.log(res,'kkkkkkkkkkkk')
                  this.xxdylist = res.data.data.list
                  this.searchLoading = false;
              }).catch( res => {
                  this.searchLoading = false;
              })
          },
          xxdy() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					 yhid:logininfo.id,
                     xxid:logininfo.xxid,
					 xxdy:this.checkList+''
				});
				//执行
				this.axios.post(this.$store.state.api + 'ls/updatexxdy', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.getdl();
							this.$emit('close', { type: 'add', cancel: false });
						    this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
						    this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},
			submit(ishow) {　
				this.$store.state.gnlist.pcqh = ishow;
				this.cancel();
			}　,
			getCheckedKeys() {
				var str = "";
				//首页模块
				if(this.qxbtn.syysbj) str += "syysbj,";
				if(this.qxbtn.syzsbj) str += "syzsbj,";
				if(this.qxbtn.syjscj) str += "syjscj,";
				if(this.qxbtn.sykbqqbk) str += "sykbqqbk,";
				if(this.qxbtn.sycwtj) str += "sycwtj,";
				if(this.qxbtn.sylscwtfsh) str += "sylscwtfsh,";
				if(this.qxbtn.sykscjtj) str += "sykscjtj,";
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					pcpb: '1',
					code:'',
					mkids: str,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'ls/dlsz', params2)
					.then(res => {
						this.$message.warning("界面即将应用您的新配置，请稍等..")
						this.getdl();
					})
			},
			getdl() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'ls/sxym', params2)
					.then(res => {
						localStorage.setItem('logininfo', JSON.stringify(res.data.data.list[0]))
						this.$emit('close', { type: 'add',cancel: true})
						location.reload()
					})
			},
			getzdycdlist(){
				var str = this.c1+","+this.c2+","+this.c3+","+this.c4+","+this.c5+","+this.c6+",";
				var logininfo = JSON.parse(localStorage.logininfo) ;
				var params3 = qs.stringify({
					code:str,
					yhid:logininfo.id,
					xxid:logininfo.xxid
				});
					this.searchLoading = true;
					this.axios.post(this.$store.state.api + 'ls/gxhcd',params3)
					.then( res => {
						if(res.data.code == 1) {
							this.$message.warning("界面即将应用您的新配置，请稍等..")
								this.getdl();
 								this.$emit('close', { type: 'add', cancel: false });
 								this.$store.state.loading = false;
 							} else {
 								this.$message.warning(res.data.msg);
 							}
					}).catch( res => {
						  this.$message.danger("服务器异常!")
					      this.searchLoading = false;
					})
			},
			cancel() {
				this.$emit('close', {type: 'add',cancel: true})
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.but {
			width: 100%;
			text-align: center;
		}
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt {
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			background: #50BFFF;
			margin-bottom: 20px;
			color: white;
			text-align: left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.submit {
			width: 120px;
		}
		.sz {
			width: 100%;
			margin: 0 auto;
		}
		td {
			margin-right: 10px;
		}
		.check2 {
			display: inline-block;
		}
		.form {
			text-align: center;
			margin-top: 20px;
		}
	}
</style>